from digits import digits

def digitsPowerSum(n, power):  
    return sum(x**power for x in digits(n))

power = 5

n = 1
while n * (9**power) >= 10**n:
    n += 1

limit = n * 9**power
total = 0

for i in xrange(2, limit + 1):
    if i == digitsPowerSum(i, power):
        print i
        total += i

print "Total:", total
